05. Java Basic APIs - Binary Search, Recursion, Big-O Notation

Binary Search

035ND C01 L01 A04 BINARY SEARCH

Binary Search Coding Exercise

Task Description:

Please complete the coding questions using binary search.

Search for the target in a sorted array, and return the index. If the target is not in this array, return -1.

Example:

Input: [1, 5, 7, 8, 9, 11, 18, 19, 20, 25], target=11, output=5.

Input: [1, 2, 3, 4, 5], target=10, output=-1

public static int findTarget(int[] arr, int target) {
}
Task List:

Task Feedback:

Great! Check my solution here: Github: https://github.com/udacity/JDND/tree/master/exercises/c1/exercises

Recursion

035ND C01 L01 A05 RECURSION

Recursion Exercise

Task Description:

Write a permutation of [1, 2, 3] (permutation gives several possible variations, in which a set or number of things can be ordered or arranged).

Give an array with unique integers, print all permutations.

Example

Input: [1, 2], print 12, 21

Input: [1, 2, 3], print 123, 132, 213, 231, 312, 321.

public static void printPermutn(int[] arr, int index) {
}
Task List:

Big-O Notation

035ND C01 L01 A06 BIG O NOTATION

Check the following link for a quick summary of the time complexity:

https://tinyurl.com/y5y2vrh6

Big-O Notation Quiz1

What is the time complexity for searching a target in an unsorted 2D m * n matrix

SOLUTION: O(m * n)

Big-O Notation Quiz2

What is the time complexity of the following function fun()?

int fun(int n) 
{     
    for (int i = 1; i <= n; i++) 
    { 
        for (int j = 1; j < n; j += i) 
        { 
            // Some O(1) task 
        } 
    }     
} 
SOLUTION: O(nlog(n))